package com.projects.android.views;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.projects.android.R;
import com.projects.android.adapters.SelectedFoodsAdapter;
import com.projects.android.utils.SelectedItems;
import com.projects.android.utils.Utils;

public class Cart extends ListActivity implements OnClickListener {
	public static Button btnCheckOut;
	public static Cart CartView;
	private TextView lblRestaurant;
	private TextView lblShipPlace;
	private Intent intent;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.cart);
		initFrm();
		loadData();
	}

	public void initFrm() {
		btnCheckOut = (Button) findViewById(R.id.btnCheckout);
		btnCheckOut.setEnabled(false);
		btnCheckOut.setOnClickListener(this);
		
		lblRestaurant = (TextView) findViewById(R.id.lblCartRestaurant);
		lblShipPlace = (TextView) findViewById(R.id.lblCartShipPlace);
		lblRestaurant.setText(SelectedItems.SelectedRestaurant.getName());
		lblShipPlace.setText(SelectedItems.SelectedRestaurant.getDeliveryDistricts());
	}

	public void loadData() {
		// Init data
		if (SelectedItems.SelectedFoods != null) {
			Cart.CartView = this;
			SelectedFoodsAdapter adapter = new SelectedFoodsAdapter(this,
					R.layout.selectedfooditem, R.id.lblSelectedFoodName,
					SelectedItems.SelectedFoods);
			setListAdapter(adapter);
			getListView().setTextFilterEnabled(true);
			if (SelectedItems.SelectedFoods.size() == 0) {
				btnCheckOut.setEnabled(false);
			} else {
				btnCheckOut.setEnabled(true);
			}
		}
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btnCheckout:
			intent = Utils.browseIntent(this, "CheckoutInfo");
			startActivity(intent);
			break;
		}
	}
}
